package zzps.exeed.kernel.holder;

import zzps.exeed.kernel.core.AppContext;
import zzps.exeed.kernel.core.Plugin;
import zzps.exeed.kernel.core.Sort;
import zzps.exeed.kernel.tool.ReflectTool;

import java.util.Arrays;
import java.util.Comparator;

public class PluginHolder {
    private String className;
    private ClassLoader classLoader;
    private int order = 0;
    private Plugin plugin;

    public PluginHolder(String className, ClassLoader classLoader) {
        this.className = className;
        this.classLoader = classLoader;
    }

    public void start(AppContext context) {
        plugin.start(context);
    }

    public void stop() {
        plugin.stop();
    }

    public void init(AppContext context) {
        Object o = ReflectTool.newInstance(className, classLoader);
        plugin = (Plugin) o;
        plugin.conflict();
    }

    public Plugin getPlugin() {
        return plugin;
    }

    public static int sort(PluginHolder firstHolder, PluginHolder secondHolder) {
        Plugin first = firstHolder.plugin;
        Plugin second = secondHolder.plugin;
        return Sort.sort(first,second);
    }
}
